// pages/real/components/waterfallFlow/index.js
const app = getApp()
const utils = require('../../../../utils/util.js')
import Dialog from '../../../../vant-weapp/dist/dialog/dialog';
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    leftList:{
      type:Array,
      value:"default value"
    },
    rightList:{
      type:Array,
      value:"default value"
    },
    types:{
      type:String,
      value:""
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    deleteButFlag:false
  },

  /**
   * 组件的方法列表
   */
  methods: {
    closeDownDage(){
      this.setData({
        deleteButFlag:false
      })
    },
    cancelCollect(e){
      const {item}=e.currentTarget.dataset
      console.log(item)
      const unionid=wx.getStorageSync("unionid")
      const str={
        createBy:unionid,
        id:item.id
      }
      utils.$http(app.globalData.api.realityContributeUnKeep, str, 'POST', true, 'JSON').then(res => {
        wx.showToast({
          title: '取消收藏成功',
          type: 'success'
        })
        app.getPrePage().handleCancelCollect()
     })
    },
    showDeleteBut(e){
      console.log(e)
      const { leftList , rightList} =this.properties
      const {dr,item}=e.currentTarget.dataset
      if(dr==='left'){
        leftList.forEach(ll=>{
         if(ll.id===item.id){
           ll.deleteFlag=true
         }else{
          ll.deleteFlag=false
         }
        })
        this.setData({
          leftList,deleteButFlag:true
        })
      }else{
        rightList.forEach(rr=>{
          if(rr.id===item.id){
            rr.deleteFlag=true
          }else{
            rr.deleteFlag=false
           }
         })
         this.setData({
          rightList,deleteButFlag:true
        })
      }
    },
    closeDeleteBut(){
      this.setData({
        deleteButFlag:false
      })
    },
    handleDelete(option){
      // this.setData({
      //   deleteButFlag:false
      // })
      const item=option.currentTarget.dataset.item
      this.triggerEvent('fatherMethod',item.id)
    },
    goDetailPage(option){
      const {types} =this.properties
      const list=option.currentTarget.dataset.val
      if(types==='my'){
        if(list.approveState==='0'){
          return
        }else if(list.approveState==='1'){
          this.handlePubRequest(list)
        }else if(list.approveState==='2'){
          app.getPrePage().handleShowReason()
        }
      }else{
        this.handlePubRequest(list)
      }
    },
    handlePubRequest(list){
      const userInfo=wx.getStorageSync('userInfo')
      const str={
        id:list.id,
        createBy:userInfo.unionId
      }
      if(list.contributeType==0){
        wx.navigateTo({
          url: '/pages/real/makeAtlas/index?id='+list.id,
          success: function(res) {
            // 通过eventChannel向被打开页面传送数据
            // res.eventChannel.emit('casepage', { data })
          }
        })
      }else{
        wx.navigateTo({
          url: '/pages/real/videoDetails/index?id='+list.id,
          success: function(res) {
            // 通过eventChannel向被打开页面传送数据
            // res.eventChannel.emit('casepage', { data })
          }
        })
      }
      utils.$http(app.globalData.api.getRealAddBrowse, str, 'POST', true, 'JSON').then(res => {

      })
    }
  }
})
